//
//  BIDSectionHeaderForStudentListView.m
//  EducationAssistant
//
//  Created by mal on 15/9/13.
//  Copyright (c) 2015年 cnsoft. All rights reserved.
//

#import "BIDSectionHeaderForMemberListView.h"
#import "BIDGlobalMethods.h"

@interface BIDSectionHeaderForMemberListView()
{
    BOOL _bSelect;
}
@end

@implementation BIDSectionHeaderForMemberListView
@synthesize flagLabel;
@synthesize nameLabel;
@synthesize checkboxBtn;
@synthesize delegate;
@synthesize section;
@synthesize imgView;

- (void)awakeFromNib
{
    [imgView setImage:[UIImage imageNamed:@"check_choose.png"]];
    _bSelect = YES;
    flagLabel.clipsToBounds = YES;
    flagLabel.layer.cornerRadius = CGRectGetWidth(flagLabel.frame)/2;
    //
    _redDotLabel.clipsToBounds = YES;
    _redDotLabel.layer.cornerRadius = CGRectGetWidth(_redDotLabel.frame)/2;
    
    UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapHandler:)];
    tapGR.numberOfTapsRequired = 1;
    tapGR.numberOfTouchesRequired = 1;
    [self addGestureRecognizer:tapGR];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (void)tapHandler:(UITapGestureRecognizer*)gr
{
    [delegate sectionHeaderTapAtIndex:section];
}

- (void)choose
{
    _bSelect = YES;
    [imgView setImage:[UIImage imageNamed:@"check_choose.png"]];
}

- (void)inchoose
{
    _bSelect = NO;
    [imgView setImage:[UIImage imageNamed:@"check_inchoose.png"]];
}

- (void)hideCheckbox
{
    checkboxBtn.hidden = YES;
    imgView.hidden = YES;
}

- (void)showRedDot:(BOOL)bShow
{
    _redDotLabel.hidden = !bShow;
}

- (void)setNameLabelText:(NSString*)name
{
    if(name.length>0)
    {
        _redDotLabel.hidden = NO;
        nameLabel.text = name;
        CGFloat width = [BIDGlobalMethods getWidthWithString:name font:nameLabel.font constraintSize:CGSizeMake(149.f, 21.f)];
        _widthForNameLabelConstraint.constant = width;
        [self layoutIfNeeded];
    }
    else
    {
        _redDotLabel.hidden = YES;
    }
}

- (IBAction)btnDownHandler:(id)sender
{
    if(_bSelect)
    {
        _bSelect = NO;
        [imgView setImage:[UIImage imageNamed:@"check_inchoose.png"]];
    }
    else
    {
        _bSelect = YES;
        [imgView setImage:[UIImage imageNamed:@"check_choose.png"]];
    }
    [delegate sectionHeaderSelectAtIndex:section selected:_bSelect];
}

@end
